package ru.aslanov.schedule.model;

import com.google.appengine.api.datastore.KeyFactory;

import javax.jdo.annotations.*;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * Created: Feb 3, 2010 9:46:09 PM
 *
 * @author Sergey Aslanov
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class Entity implements Serializable {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    private String encodedKey;

    public String getEncodedKey() {
        return encodedKey;
    }

    protected String getLocalId() {
        final com.google.appengine.api.datastore.Key key = KeyFactory.stringToKey(encodedKey);
        return key.getKind() + key.getId();
    }

}
